package loader
{
	import events.MyEvent;
	
	import flash.errors.IOError;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	
	/**
	 * ...
	 * @author FireKnight
	 */
	public class AnsiTxtLoader extends TxtLoader
	{
		
		public function AnsiTxtLoader(s:String, b:Function, target:IEventDispatcher = null)
		{
			super(s, b, target);
		
		}
		
		override protected function loadFile(s:String):void
		{
			removeLoader();
			myLoader = new URLLoader();
			myLoader.dataFormat = "binary";
			myLoader.load(new URLRequest(s));
			
			myLoader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
			myLoader.addEventListener(IOErrorEvent.IO_ERROR, handleIoError, false, 0, true);
		}
		
		override protected function onComplete(e:Event):void
		{
			
			var ld:URLLoader = e.target as URLLoader;
			
			var BA:ByteArray = new ByteArray;
			BA.writeBytes(ld.data);
			BA.position = 0;
			var str:String=BA.readMultiByte(BA.length, "utf8");
			
			ld.close();
			this.callBack(str);
		}
	
	}

}